package com.liangxy.news.model;

import androidx.annotation.NonNull;
import androidx.room.Entity;
import androidx.room.ForeignKey;
import androidx.room.Index;

/**
 * Entity for user browsing history
 */
@Entity(
        tableName = "user_history",
        primaryKeys = {"user_id", "news_id"},
        indices = {
                @Index("user_id"),
                @Index("news_id")
        },
        foreignKeys = {
                @ForeignKey(
                        entity = User.class,
                        parentColumns = "id",
                        childColumns = "user_id",
                        onDelete = ForeignKey.CASCADE
                ),
                @ForeignKey(
                        entity = News.class,
                        parentColumns = "uniquekey",
                        childColumns = "news_id",
                        onDelete = ForeignKey.CASCADE
                )
        }
)
public class UserHistory {
    
    @NonNull
    private String user_id;
    
    @NonNull
    private String news_id;
    
    private long timestamp;
    
    public UserHistory(@NonNull String user_id, @NonNull String news_id, long timestamp) {
        this.user_id = user_id;
        this.news_id = news_id;
        this.timestamp = timestamp;
    }
    
    @NonNull
    public String getUser_id() {
        return user_id;
    }
    
    public void setUser_id(@NonNull String user_id) {
        this.user_id = user_id;
    }
    
    @NonNull
    public String getNews_id() {
        return news_id;
    }
    
    public void setNews_id(@NonNull String news_id) {
        this.news_id = news_id;
    }
    
    public long getTimestamp() {
        return timestamp;
    }
    
    public void setTimestamp(long timestamp) {
        this.timestamp = timestamp;
    }
} 